<template>
    <div class="body">
        <div class="n_filter font13">
            <a
                class="nf_item"
                :class="{ checked: type == 0 }"
                @click="turnNav(0)"
                >全部职位</a
            >
            <a
                class="nf_item"
                :class="{ checked: type == 1 }"
                @click="turnNav(1)"
                >发布中的</a
            >
            <a
                class="nf_item"
                :class="{ checked: type == 2 }"
                @click="turnNav(2)"
                >未显示的</a
            >
        </div>

        <div
            class="job js-actionParent"
            v-for="(item, index) in pageListInfo.comment_list"
            :key="index"
        >
            <div
                class="info"
                @click="
                    $router.push({
                        path: '/jobFindDetail',
                        query: { id: item.id },
                    })
                "
            >
                <div class="item_name_line">
                    <a class="item_name substring font15">{{
                        item.jobs_name
                    }}</a>
                    <!--紧急-->
                    <!--置顶-->
                    <div class="clear"></div>
                    <div class="item_status font12"></div>
                </div>

                <div class="line-two substring font12">
                    {{ item.district_cn }} | {{ item.experience_cn }}|
                    {{ item.education_cn }} | {{ item.amount }} |
                    {{ item.wage_cn }}
                </div>
                <div class="line-three font12">
                    <div class="pic apply">投递{{ item.applys }}次</div>
                    <div class="pic browse">浏览{{ item.click }}次</div>
                    <div class="pic refresh">
                        {{ item.refreshtime }}
                    </div>
                    <div class="clear"></div>
                </div>
            </div>
            <div class="handler font14">
                <div
                    class="item"
                    @click="
                        $router.push({
                            path: '/personDetail',
                            query: { id: item.id },
                        })
                    "
                >
                    <span>简历</span>
                </div>
                <div
                    class="item"
                    @click="
                        $router.push({
                            path: '/publishJob',
                            query: { id: item.id },
                        })
                    "
                >
                    <span>修改</span>
                </div>
                <div
                    class="item"
                    @click="closeJob(item.id)"
                    v-show="item.display != 2"
                >
                    <span>关闭</span>
                </div>
                <div
                    class="item"
                    @click="huifuJob(item.id)"
                    v-show="item.display == 2"
                >
                    <span>恢复</span>
                </div>
                <div class="item" @click="deleZhiwei(item.id)">
                    <span class="last">删除</span>
                </div>
            </div>
        </div>

        <!-- 分页 -->
        <component
            :is="'Pagination'"
            :pageInfo="pageInfo"
            @pageNext="pageNext"
            @changePageStatus="changePageStatus"
        ></component>
        <!-- 更多 -->
        <van-action-sheet
            v-model="gengduoKey"
            :actions="gengduoactions"
            @select="gengduoSelect"
            cancel-text="取消"
            :duration="0.2"
        />
        <!-- 缺省页面 -->
        <component
            :is="'ContentNone'"
            v-if="pageListInfo.comment_list.length == 0 && pageInfo.pageSatus"
        ></component>
    </div>
</template>

<script>
import { axiosGet, axiosPost } from '../../axios';
import { Toast, Dialog } from 'vant';
export default {
    name: '',
    data() {
        return {
            type: 0,
            gengduoKey: false,
            gengduoVal: '',
            gengduoactions: [{ name: '修改' }, { name: '删除' }],

            pageListInfo: {
                comment_list: [],
            },
            // 分页组件信息
            pageInfo: {
                pagingText: '',
                pageNum: 1,
                pageSatus: true,
            },
        };
    },
    computed: {},
    mounted() {
        this.pageListInfo.comment_list = [];
        this.pageInfo.pageSatus = false;
        this.getList();
    }, //
    methods: {
        huifuJob(id) {
            Dialog.confirm({
                title: '',
                message: '确定要恢复职位吗？',
            })
                .then(() => {
                    axiosPost(
                        '/apis/company/jobs_display',
                        {
                            id: id,
                        },
                        (res) => {
                            Toast({
                                message: res.msg,
                                duration: 2000,
                            });
                            if (res.status != 1) {
                                return;
                            }
                            this.pageListInfo.comment_list = [];
                            this.pageInfo.pageSatus = false;
                            this.getList();
                        }
                    );
                })
                .catch(() => {
                    // on cancel
                });
        },
        closeJob(id) {
            Dialog.confirm({
                title: '',
                message: '确定要关闭职位吗？',
            })
                .then(() => {
                    axiosPost(
                        '/apis/company/jobs_close',
                        {
                            id: id,
                        },
                        (res) => {
                            Toast({
                                message: res.msg,
                                duration: 2000,
                            });
                            if (res.status != 1) {
                                return;
                            }
                            this.pageListInfo.comment_list = [];
                            this.pageInfo.pageSatus = false;
                            this.getList();
                        }
                    );
                })
                .catch(() => {
                    // on cancel
                });
        },
        // 删除职位
        deleZhiwei(id) {
            Dialog.confirm({
                title: '',
                message: '您真的要删除职位吗？',
            })
                .then(() => {
                    axiosPost(
                        '/apis/company/jobs_delete',
                        {
                            id: id,
                        },
                        (res) => {
                            Toast({
                                message: res.msg,
                                duration: 2000,
                            });
                            if (res.status != 1) {
                                return;
                            }
                            this.pageListInfo.comment_list = [];
                            this.pageInfo.pageSatus = false;
                            this.getList();
                        }
                    );
                })
                .catch(() => {
                    // on cancel
                });
        },
        turnNav(id) {
            this.type = id;
            this.pageListInfo.comment_list = [];
            this.pageInfo.pageSatus = false;
            this.getList();
        },
        // 更多弹窗
        gengduoSelect() {
            // console.log(item);
            this.gengduoKey = false;
        },

        // 分页组件修改状态
        changePageStatus(data) {
            this.pageInfo.pageSatus = data;
        },
        // 分页组件回调
        pageNext(data) {
            this.pageInfo.pageNum = data;
            this.getList(data); // 根据type获取订单
        },
        // 获取职位列表
        getList(page = 1, page_size = 10) {
            axiosGet(
                '/apis/company/jobs_list',
                {
                    type: this.type,
                    page: page,
                    page_size: page_size,
                },
                (res) => {
                    // console.log(res);
                    if (res.status != 1) {
                        return Toast({
                            message: res.msg,
                            duration: 2000,
                        });
                    }

                    // 分页处理
                    if (
                        res.data.jobs_list.page_params.nowPage ==
                        res.data.jobs_list.page_params.totalPages
                    ) {
                        this.pageInfo.pagingText = '没有更多啦！';
                    } else {
                        this.pageInfo.pagingText = '商品加载中...';
                    }
                    this.pageInfo.pageSatus = true;

                    // 数据处理
                    for (let i in res.data.jobs_list.list) {
                        let element = res.data.jobs_list.list[i];
                        this.pageListInfo.comment_list.push(element);
                    }

                    this.pageListInfo.page = res.data.jobs_list.page_params;
                }
            );
        },
    },
};
</script>
<style lang="less" src="../../assets/css/jobCommon.less" scope></style>
<style lang="css" src="../../assets/css/van-action-sheet.css" scope></style>
<style lang="less" scope>
.van-action-sheet__cancel,
.van-action-sheet__item {
    text-align: center;
}
</style>
